/*
** endgame.c for zappy in /home/guidet_m/TECK2/projets/zappy/server_zappy
** 
** Made by michael guidet
** Login   <guidet_m@epitech.net>
** 
** Started on  Mon Jul  4 15:38:22 2011 michael guidet
** Last update Mon Jul 11 10:15:30 2011 michael guidet
*/

#include "server.h"

void		check_endgame(t_fd *fd, t_env *e, char *cmd)
{
  int		i;
  t_player_list	*tmp;
  int		cpt;

  cmd = cmd;
  for (i = 0; e->teams[i].name; i++)
    {
      cpt = 0;
      for (tmp = e->teams[i].ia_players; tmp; tmp = tmp->next)
	if (tmp->drone->level == 8)
	  cpt++;
      if (cpt >= 6)
	endgame(fd, e);
    }
}

void	endgame(t_fd *fd, t_env *e)
{
  t_fd	*tmp;
  char	cmd2[BUF_SIZE];

  sprintf(cmd2, "seg %s\n", fd->pl->team);
  for (tmp = e->fd; tmp; tmp = tmp->next)
    {
      if (tmp->type == GRAPH)
	x_int(-1, send(tmp->fd, cmd2, strlen(cmd2), 0), "send");
      dead(tmp, e);
    }
  clean_fd(e);
  exit(-1);
}
